<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js </title>
    <script>
        function checkName(userName) {
            if (userName === ''){
                alert("用户名不能为空");

            }
            document.getElementById("prompt2").innerHTML = "名字："+userName;
        }

        function focusName(userName) {
           document.getElementById("prompt1").innerHTML = "名字："+userName;
        }
    </script>
</head>
<body onload="alert('页面全部加载完成')">
    用户名:<input type="text" value="小宝" onfocus="focusName(this.value)"/>

    <span id="prompt1"></span>
    <br/>

    用户名:<input type="text" value="小宝2"  onblur="checkName(this.value)"/>
    <span id="prompt2"></span>
</body>
</html>